import difflib


def compare_text_files(file1_path, file2_path):
    """
    比较两个文本文件的内容差异，并打印差异部分。

    参数:
        file1_path (str): 第一个文件的路径
        file2_path (str): 第二个文件的路径
    """
    # 打开并读取两个文件的内容
    with open(file1_path, "r", encoding="utf-8") as file1:
        file1_lines = file1.readlines()

    with open(file2_path, "r", encoding="utf-8") as file2:
        file2_lines = file2.readlines()

    # 使用difflib生成差异
    diff = difflib.unified_diff(
        file1_lines, file2_lines, fromfile=file1_path, tofile=file2_path, lineterm=""
    )

    # 打印差异
    print("\n文件内容差异：")
    for line in diff:
        print(line)


# 示例用法
if __name__ == "__main__":
    file1_path = "matrix\\大一下\\w3\\data (1).txt"
    file2_path = "matrix\\大一下\\w3\\data.txt"
    compare_text_files(file1_path, file2_path)
